package com.cbtx.utils

import android.content.Context
import com.cbtx.utils.ui.LoadingDialog

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/7/1 3:21 PM
 * desc   :
 */
object LoadingDialogUtil {

    private var loadingDialog: LoadingDialog? = null

    fun showDialog(context: Context, content: String, isTouch: Boolean) {
        if (loadingDialog == null || !loadingDialog?.isShowing!!) {
            loadingDialog = LoadingDialog(context, content)
            loadingDialog!!.setCanceledOnTouchOutside(isTouch)
            loadingDialog!!.show()
        } else {
            loadingDialog?.setDialogContent(content)
        }
    }

    fun showDialog(context: Context, content: String) {
        showDialog(context, content, true)
    }


    /**
     * 关闭dialog
     */
    fun closeDialog() {
        if (loadingDialog != null && loadingDialog!!.isShowing) {
            loadingDialog!!.dismiss()
            loadingDialog = null
        }
    }
}